﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cotizav.PRESENTACION.Reporte.Parametros.Cliente
{
    public partial class Rep_ClienteGeneral : UserControl
    {
        private CtrlClientes ctCliente;
        private CtrlProvincia ctProvincia;
        private CtrlDistrito ctDistrito;
        private CtrlSector ctSector;
        private CtrlSucursal ctSucursal;   

        public Rep_ClienteGeneral()
        {
            InitializeComponent();

            ctCliente = new CtrlClientes();
            ctProvincia = new CtrlProvincia();
            ctDistrito = new CtrlDistrito();
            ctSector = new CtrlSector();
            ctSucursal = new CtrlSucursal();    
        }

        private void Rep_ClienteGeneral_Load(object sender, EventArgs e)
        {
            cmbProvincia.DataSource = null;
            cmbProvincia.DataSource = ctProvincia.getListProvincia();
            cmbProvincia.DisplayMember = "nombreProvincia";
            cmbProvincia.ValueMember = "idProvincia";
            cmbProvincia.SelectedIndex = -1;

            cmbSector.DataSource = null;
            cmbSector.DataSource = ctSector.getListSector();
            cmbSector.DisplayMember = "nombreSector";
            cmbSector.ValueMember = "idSector";
            cmbSector.SelectedIndex = -1;

            cmbSucursal.DataSource = null;
            cmbSucursal.DataSource = ctSucursal.getListSucursal();
            cmbSucursal.DisplayMember = "nombreSucursal";
            cmbSucursal.ValueMember = "idSucursal";
            cmbSucursal.SelectedIndex = -1;
        }

        private void chkRuc_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRuc.Checked)
            {
                txtRuc.Enabled = true;
            }
            else
            {
                txtRuc.Enabled = false;
            }
        }

        private void chkProvincia_CheckedChanged(object sender, EventArgs e)
        {
            if (chkProvincia.Checked)
            {
                cmbProvincia.Enabled = true;
            }
            else
            {
                cmbProvincia.Enabled = false;
            }
        }

        private void chkDistrito_CheckedChanged(object sender, EventArgs e)
        {
            if (chkDistrito.Checked)
            {
                cmbDistrito.Enabled = true;
            }
            else
            {
                cmbDistrito.Enabled = false;
            }
        }

        private void chkRazonSocial_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRazonSocial.Checked)
            {
                txtRazonSocial.Enabled = true;
            }
            else
            {
                txtRazonSocial.Enabled = false;
            }
        }

        private void chkSector_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSector.Checked)
            {
                cmbSector.Enabled = true;
            }
            else
            {
                cmbSector.Enabled = false;
            }
        }

        private void chkSucursal_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSucursal.Checked)
            {
                cmbSucursal.Enabled = true;
            }
            else
            {
                cmbSucursal.Enabled = false;
            }
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string ruc = chkRuc.Checked ? txtRuc.Text : null;
            string razonSocial = chkRazonSocial.Checked ? txtRazonSocial.Text : null;
            string idProvincia = chkProvincia.Checked ? cmbProvincia.SelectedValue != null ? cmbProvincia.SelectedValue.ToString() : null : null;
            string idDistrito = chkDistrito.Checked ? cmbDistrito.SelectedValue != null ? cmbDistrito.SelectedValue.ToString() : null : null;
            string idSector = chkSector.Checked ? cmbSector.SelectedValue != null ? cmbSector.SelectedValue.ToString() : null : null;
            string idSucursal = chkSucursal.Checked ? cmbSucursal.SelectedValue != null ? cmbSucursal.SelectedValue.ToString() : null : null;

            DataTable result = ctCliente.getListClientexRepGeneral(ruc, razonSocial, idProvincia, idDistrito, idSector, idSucursal);

            IUReporte iurep = this.ParentForm as IUReporte;
            iurep.showClienteRepGeneral("Clientes", result);
        }
    }
}
